package com.cheer.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cheer.dao.ExMatchHistoryDao;
import com.cheer.enums.OaIntegralRuleEnum;
import com.cheer.param.ExMatchHistoryEntity;
import com.cheer.service.ExMatchHistoryService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ExMatchHistoryServiceImpl extends ServiceImpl<ExMatchHistoryDao,
        ExMatchHistoryEntity> implements ExMatchHistoryService {

    @Override
    public Boolean isHaveAnswer(Long userId, Date date) {
        // 查询
        List<ExMatchHistoryEntity> list = list(new QueryWrapper<ExMatchHistoryEntity>().lambda()
                .eq(ExMatchHistoryEntity::getUserId, userId)
                .ge(ExMatchHistoryEntity::getCreateTime, DateUtil.beginOfDay(new Date())));
        return CollectionUtil.isNotEmpty(list) && list.size() >= OaIntegralRuleEnum.MATCH.getMax();
    }
}
